import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isUndefined from "lodash/isUndefined";

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _class, _class2;

/**
 * Company - 分配安全组-数据权限tab页 - 公司
 * @date: 2019-12-23

 */
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { Bind } from 'lodash-decorators';
import { Button, Form, Input, Table, Row, Col } from 'antd';
import { Button as ButtonPermission } from 'components/Permission';
import { operatorRender, yesOrNoRender } from 'utils/renderer';
import { tableScrollWidth } from 'utils/utils';
import intl from 'utils/intl';
import { EDIT_FORM_ITEM_LAYOUT_COL_2, SEARCH_FORM_ROW_LAYOUT, FORM_COL_3_LAYOUT, SEARCH_COL_CLASSNAME } from 'utils/constants';
import styles from "./index.less?modules";
var FormItem = Form.Item;
var Company = (_dec = connect(function (_ref) {
  var secGrpAuthorityCompany = _ref.secGrpAuthorityCompany,
      loading = _ref.loading;
  return {
    secGrpAuthorityCompany: secGrpAuthorityCompany,
    fetchLoading: loading.effects['secGrpAuthorityCompany/fetchAuthorityCompanyAndExpand']
  };
}), _dec2 = Form.create({
  fieldNameProp: null
}), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(Company, _PureComponent);

  var _super = _createSuper(Company);

  function Company(props) {
    var _this;

    _classCallCheck(this, Company);

    _this = _super.call(this, props);
    _this.state = {
      expanded: true
    };
    return _this;
  }

  _createClass(Company, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.queryValue();
    }
  }, {
    key: "queryValue",
    value: function queryValue() {
      var _this2 = this;

      var _this$props = this.props,
          form = _this$props.form,
          dispatch = _this$props.dispatch,
          secGrpId = _this$props.secGrpId,
          roleId = _this$props.roleId;
      form.validateFields(function (err, fieldsValue) {
        if (!err) {
          _this2.setState({
            expanded: false
          });

          dispatch({
            type: 'secGrpAuthorityCompany/fetchAuthorityCompanyAndExpand',
            payload: _objectSpread(_objectSpread({}, fieldsValue), {}, {
              secGrpId: secGrpId,
              roleId: roleId,
              authorityTypeCode: 'COMPANY'
            })
          });
        }
      });
    }
  }, {
    key: "handleReset",
    value: function handleReset() {
      var form = this.props.form;
      form.resetFields();
    }
    /**
     *点击展开节点触发方法
     *
     * @param {*Boolean} expanded 展开收起标志
     * @param {*Object} record 行记录
     */

  }, {
    key: "onExpand",
    value: function onExpand(expanded) {
      var record = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      var _this$props2 = this.props,
          dispatch = _this$props2.dispatch,
          _this$props2$secGrpAu = _this$props2.secGrpAuthorityCompany.expandedRowKeys,
          expandedRowKeys = _this$props2$secGrpAu === void 0 ? [] : _this$props2$secGrpAu;
      dispatch({
        type: 'secGrpAuthorityCompany/updateExpanded',
        payload: expanded ? expandedRowKeys.concat(record.id) : expandedRowKeys.filter(function (o) {
          return o !== record.id;
        })
      });
    }
    /**
     *全部展开和收起
     */

  }, {
    key: "handleExpand",
    value: function handleExpand() {
      var _this$props3 = this.props,
          dispatch = _this$props3.dispatch,
          _this$props3$secGrpAu = _this$props3.secGrpAuthorityCompany.originList,
          originList = _this$props3$secGrpAu === void 0 ? [] : _this$props3$secGrpAu;
      var expanded = this.state.expanded;
      dispatch({
        type: 'secGrpAuthorityCompany/updateExpanded',
        payload: expanded ? originList.map(function (list) {
          return list.id;
        }) : []
      });
      this.setState({
        expanded: !expanded
      });
    }
    /**
     * 屏蔽/取消屏蔽公司权限
     * @param {object} record - 表格行数据
     */

  }, {
    key: "handleShield",
    value: function handleShield(record) {
      var secGrpDclLineId = record.secGrpDclLineId,
          shieldFlag = record.shieldFlag;
      var _this$props$onShield = this.props.onShield,
          onShield = _this$props$onShield === void 0 ? function (e) {
        return e;
      } : _this$props$onShield;
      var shieldData = {
        shieldFlag: shieldFlag,
        authorityId: secGrpDclLineId,
        authorityType: 'DCL'
      };
      onShield(shieldData, this.queryValue);
    }
    /**
     *渲染查询结构
     *
     * @returns
     */

  }, {
    key: "renderForm",
    value: function renderForm() {
      var _this3 = this;

      var getFieldDecorator = this.props.form.getFieldDecorator; // const { updateLoading, path } = this.props;

      var expanded = this.state.expanded;
      return /*#__PURE__*/React.createElement(Form, {
        layout: "inline"
      }, /*#__PURE__*/React.createElement(Row, Object.assign({
        type: "flex",
        gutter: 24,
        align: "bottom"
      }, SEARCH_FORM_ROW_LAYOUT), /*#__PURE__*/React.createElement(Col, FORM_COL_3_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('ciam.authority.model.authorityCompany.name').d('名称')
      }, EDIT_FORM_ITEM_LAYOUT_COL_2), getFieldDecorator('dataName')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, FORM_COL_3_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('ciam.authority.model.authorityCompany.dataCode').d('代码')
      }, EDIT_FORM_ITEM_LAYOUT_COL_2), getFieldDecorator('dataCode')( /*#__PURE__*/React.createElement(Input, {
        typeCase: "upper",
        trim: true,
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_3_LAYOUT, {
        className: SEARCH_COL_CLASSNAME
      }), /*#__PURE__*/React.createElement(FormItem, null, /*#__PURE__*/React.createElement(Button, {
        onClick: this.handleReset,
        style: {
          marginRight: 8
        }
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        onClick: this.queryValue,
        htmlType: "submit"
      }, intl.get('cpaas.common.button.search').d('查询'))))), /*#__PURE__*/React.createElement(Row, SEARCH_FORM_ROW_LAYOUT, /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_3_LAYOUT, {
        offset: 16
      }), /*#__PURE__*/React.createElement(FormItem, {
        className: styles['right-btn-group']
      }, /*#__PURE__*/React.createElement(Button, {
        onClick: function onClick() {
          return _this3.handleExpand();
        }
      }, expanded ? intl.get('cpaas.common.button.expand').d('展开') : intl.get('cpaas.common.button.up').d('收起'))))));
    }
  }, {
    key: "render",
    value: function render() {
      var _this4 = this;

      var _this$props4 = this.props,
          _this$props4$fetchLoa = _this$props4.fetchLoading,
          fetchLoading = _this$props4$fetchLoa === void 0 ? false : _this$props4$fetchLoa,
          _this$props4$shieldLo = _this$props4.shieldLoading,
          shieldLoading = _this$props4$shieldLo === void 0 ? false : _this$props4$shieldLo,
          path = _this$props4.path,
          _this$props4$secGrpAu = _this$props4.secGrpAuthorityCompany;
      _this$props4$secGrpAu = _this$props4$secGrpAu === void 0 ? {} : _this$props4$secGrpAu;
      var _this$props4$secGrpAu2 = _this$props4$secGrpAu.data,
          data = _this$props4$secGrpAu2 === void 0 ? [] : _this$props4$secGrpAu2,
          _this$props4$secGrpAu3 = _this$props4$secGrpAu.checkList,
          checkList = _this$props4$secGrpAu3 === void 0 ? [] : _this$props4$secGrpAu3,
          _this$props4$secGrpAu4 = _this$props4$secGrpAu.expandedRowKeys,
          expandedRowKeys = _this$props4$secGrpAu4 === void 0 ? [] : _this$props4$secGrpAu4;
      var columns = [{
        title: intl.get('ciam.authority.model.authorityCompany.dataName').d('公司/业务单元/库存组织'),
        dataIndex: 'dataName'
      }, {
        title: intl.get('ciam.authority.model.authorityCompany.dataCode').d('代码'),
        dataIndex: 'dataCode',
        width: 400
      }, {
        dataIndex: 'shieldFlag',
        title: intl.get('ciam.roleManagement.model.roleManagement.isShield').d('是否屏蔽'),
        width: 90,
        render: yesOrNoRender
      }, {
        key: 'operator',
        title: intl.get('cpaas.common.button.action').d('操作'),
        width: 100,
        fixed: 'right',
        render: function render(_, record) {
          var shieldBtn = [];

          if (!_isUndefined(record.shieldFlag)) {
            shieldBtn.push({
              key: 'shield',
              ele: /*#__PURE__*/React.createElement(ButtonPermission, {
                type: "text",
                permissionList: [{
                  code: "".concat(path, ".button.shield"),
                  type: 'button',
                  meaning: '角色管理-屏蔽访问权限'
                }],
                onClick: function onClick() {
                  return _this4.handleShield(record);
                }
              }, record.shieldFlag ? intl.get('ciam.roleManagement.view.button.cancelShield').d('取消屏蔽') : intl.get('ciam.roleManagement.view.button.shield').d('屏蔽')),
              len: record.shieldFlag ? 4 : 2,
              title: record.shieldFlag ? intl.get('ciam.roleManagement.view.button.cancelShield').d('取消屏蔽') : intl.get('ciam.roleManagement.view.button.shield').d('屏蔽')
            });
          }

          return operatorRender(shieldBtn);
        }
      }];
      return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
        className: "table-list-search"
      }, this.renderForm()), /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: "id",
        pagination: false,
        loading: fetchLoading || shieldLoading,
        dataSource: data,
        expandedRowKeys: expandedRowKeys,
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns)
        },
        rowClassName: function rowClassName(record) {
          return checkList.find(function (list) {
            return list.id === record.id;
          }) ? 'row-active' : 'row-noactive';
        },
        onExpand: this.onExpand
      }));
    }
  }]);

  return Company;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "queryValue", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "queryValue"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleReset", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleReset"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onExpand", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "onExpand"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleExpand", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "handleExpand"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleShield", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "handleShield"), _class2.prototype)), _class2)) || _class) || _class);
export { Company as default };